#! /usr/bin/python
# -*- coding: utf-8 -*-

import urllib.request
from . import city
import json

def getCityCode(name):
    cityCode = city.city.get(name)
    print(cityCode)
    if cityCode:
        return cityCode
    else:
        print("th name is err")
def getCityHtml(cityCode):
    url = (('http://www.weather.com.cn/data/cityinfo/%s.html' % cityCode))
    print(url)
    return url
def searchCityWeather(cityHtml):
    print(cityHtml)
    content = urllib.request.urlopen(cityHtml).read()
    data = json.loads(content)["weatherinfo"]
    #print ("%s %s~%s %s %s")%(data["city"],data["temp1"],data["temp2"],data["weather"],data["ptime"])
    return ("%s %s~%s %s %s")%(data["city"],data["temp1"],data["temp2"],data["weather"],data["ptime"])
    